import { PrismaClient } from '@prisma/client'
import { readBody } from 'h3'
const prisma = new PrismaClient()

export default defineEventHandler(async (event) => {
    const { user, score, content, topicId, speed } = await readBody(event)
    const u = await prisma.user.create({data: user})
    const _content = JSON.parse(content).map(item=>{
        item.answer = item.answer?.split('')?.sort().join('').toUpperCase()
        item.selected = item.selected?.split('')?.sort().join('').toUpperCase()
        return item
    })
    const post = await prisma.post.create({
        data: {
            userId: u.id,
            score: parseInt(score),
            content: JSON.stringify(_content),
            topicId: parseInt(topicId),
            speed: parseInt(speed),
        }
    })
    // 查询考试信息
    return post
})
